<?php

	class Documents{
			
		function check_auth(){
			if($pky = get('smuoi_set_pubkey')) $_COOKIE['pubkey'] = $pky;
			elseif(!isset($_COOKIE['pubkey'])) return;
			if(sn()->restore_session() && $pky) die('Hey, there '.usr()->name.'. Your pubkey is stored.');
		}	
		
		function run(){
			
			$this->check_auth();
			
			foreach(smoui_getenv_array('PREPEND') as $s) require_once DOM_DESKDIR."/scripts/$s";
		
			$rsrc = document();
		
			if(!smuoi_is_readable($rsrc)) httpE(401);
			
			$rsrc->put();
			
			foreach(smoui_getenv_array('APPEND') as $s) require_once DOM_DESKDIR."/scripts/$s";
		
			exit;
			
		}
			
	}


